﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefEquipmentSpotMaster" :model="stateEquipmentSpotMaster.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_EquipmentId_FormItem" prop="Entity.EquipmentId"
					 :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EquipmentSpotMaster_Equipment')}), trigger: 'blur' }]"
				 	:label="$t('message.autotrans._Model_EquipmentSpotMaster_Equipment')">
            <el-select v-model="stateEquipmentSpotMaster.vmModel.Entity.EquipmentId" clearable>
               <el-option v-for="item in stateEquipmentSpotMaster.AllEquipments" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_ProductId_FormItem" prop="Entity.ProductId"
											:label="$t('message.autotrans._Model_EquipmentSpotMaster_ProductId')">
            <el-select v-model="stateEquipmentSpotMaster.vmModel.Entity.ProductId" clearable>
               <el-option v-for="item in stateEquipmentSpotMaster.AllProducts" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        
        </el-form-item>

        </el-col>
<!--        <el-col :xs="24" :lg="24" class="mb20">-->
<!--        <el-form-item ref="Entity_ProductCode_FormItem" prop="Entity.ProductCode" :label="$t('message.autotrans._Model_EquipmentSpotMaster_ProductCode')">-->
<!--            <el-input v-model="stateEquipmentSpotMaster.vmModel.Entity.ProductCode" clearable></el-input>-->
<!--        </el-form-item>-->

<!--        </el-col>-->
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_MasterBarcode_FormItem" prop="Entity.MasterBarcode" :label="$t('message.autotrans._Model_EquipmentSpotMaster_MasterBarcode')"
											:rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EquipmentSpotMaster_MasterBarcode')}), trigger: 'blur' }]" >
            <el-input v-model="stateEquipmentSpotMaster.vmModel.Entity.MasterBarcode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_SpotType_FormItem" prop="Entity.SpotType" :label="$t('message.autotrans._Model_EquipmentSpotMaster_SpotType')">
            <el-select v-model="stateEquipmentSpotMaster.vmModel.Entity.SpotType" clearable>

               <el-option key="NgMaster" value="NgMaster" :label="$t('message.autotrans._Enum_SpotTypeEmum_NgMaster')"></el-option>
               <el-option key="OkMaster" value="OkMaster" :label="$t('message.autotrans._Enum_SpotTypeEmum_OkMaster')"></el-option>

            </el-select>
        </el-form-item>

        </el-col>
        <!-- <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_OpId_FormItem" prop="Entity.OpId" :label="$t('message.autotrans._Model_EquipmentSpotMaster_OpId')">
            <el-input v-model="stateEquipmentSpotMaster.vmModel.Entity.OpId" clearable></el-input>
        </el-form-item>

        </el-col> -->
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_OpCode_FormItem" prop="Entity.OpCode" :label="$t('message.autotrans._Model_EquipmentSpotMaster_OpCode')">
            <el-input v-model="stateEquipmentSpotMaster.vmModel.Entity.OpCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="24" class="mb20">
        <el-form-item ref="Entity_Active_FormItem" prop="Entity.Active" :label="$t('message.autotrans._Model_EquipmentSpotMaster_Active')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_EquipmentSpotMaster_Active')}), trigger: 'blur' }]" >
            <el-switch v-model="stateEquipmentSpotMaster.vmModel.Entity.Active" clearable></el-switch>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitEquipmentSpotMaster"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseEquipmentSpotMaster"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageEquipmentManagementEquipmentSpotMasterCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { equipmentspotmasterApi } from '/@/api/equipmentmanagement/equipmentspotmaster';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefEquipmentSpotMaster = ref();
const stateEquipmentSpotMaster = reactive({
    vmModel: {
	  Entity:{
        EquipmentId: null,
        ProductId: null,
        ProductCode: '',
        MasterBarcode: '',
        SpotType: undefined,
        OpId: null,
        OpCode: '',
        Active: true,
      },

	},
       AllProducts: [] as any[],
    AllEquipments: [] as any[],
});

// 取消
const onCloseEquipmentSpotMaster = () => {
    closeDialog();
};

// 提交
const onSubmitEquipmentSpotMaster = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefEquipmentSpotMaster.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            equipmentspotmasterApi().add(stateEquipmentSpotMaster.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    other.getSelectList('/api/ProductManagement/ProductBom/GetProducts',[],false).then(x=>{stateEquipmentSpotMaster.AllProducts = x});
    other.getSelectList('/api/EquipmentManagement/EquipmentSpotMaster/GetEquipments',[],false).then(x=>{stateEquipmentSpotMaster.AllEquipments = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

